//
//  ZhuceViewController.m
//  Xiangmu
//
//  Created by 이경인 on 2017/10/12.
//  Copyright © 2017年 LIJINGREN. All rights reserved.
//

#import "ZhuceViewController.h"
#import "LoginViewController.h"
#import "AFNetworking.h"
#import "MBProgressHUD/MBProgressHUD.h"

@interface ZhuceViewController ()
@property (nonatomic, strong) UITextField *username;
@property (nonatomic, strong) UITextField *password;
@end

@implementation ZhuceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //设置背景
    UIImageView *beijing = [[UIImageView alloc] initWithFrame:self.view.bounds];
    beijing.image = [UIImage imageNamed:@"beijing"];
    [self.view addSubview:beijing];
    
    //设置用户名
    username = [[UITextField alloc] init];
    username.frame = CGRectMake(93, 200, 175, 40);
    username.font = [UIFont boldSystemFontOfSize:20];
    username.textColor = [UIColor whiteColor];
    NSAttributedString *yhma = [[NSAttributedString alloc] initWithString:@"用户名"attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:username.font}];
    username.attributedPlaceholder = yhma;
    username.textAlignment = NSTextAlignmentCenter;
    //水平线
    UIView *line=[[UIView alloc]initWithFrame:CGRectMake(90,240, 180, 2)];
    line.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:line];
    
    //设置密码
    password = [[UITextField alloc] init];
    password.frame = CGRectMake(93, 260, 175, 40);
    password.font = [UIFont boldSystemFontOfSize:20];
    password.textColor = [UIColor whiteColor];
    NSAttributedString *mma = [[NSAttributedString alloc] initWithString:@"密码"attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:password.font}];
    password.attributedPlaceholder = mma;
    password.secureTextEntry = YES ;
    password.textAlignment = NSTextAlignmentCenter;
      //水平线
    UIView *linem=[[UIView alloc]initWithFrame:CGRectMake(90,300, 180, 2)];
    linem.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:linem];
    
   
    //注册按钮
    zhuce = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    zhuce.frame = CGRectMake(135, 350, 80, 40);
    [zhuce.layer setMasksToBounds:YES];
    [zhuce.layer setCornerRadius:20.0]; //设置矩形四个圆角半径
    [self->zhuce.layer setBorderColor:[UIColor whiteColor].CGColor];
    [zhuce setFont: [UIFont boldSystemFontOfSize:14]];
    //边框宽度
    [zhuce.layer setBorderWidth:1.0];
    [zhuce setTitleColor:[UIColor whiteColor]forState:UIControlStateNormal];
    [zhuce setTitle:@"注册" forState:UIControlStateNormal];
    [zhuce addTarget:self action:@selector(presszhuce) forControlEvents:UIControlEventTouchUpInside];
    
    //返回按钮
    fanhui = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    fanhui.frame = CGRectMake(135, 400, 80, 40);
    [fanhui.layer setMasksToBounds:YES];
    [fanhui.layer setCornerRadius:20.0]; //设置矩形四个圆角半径
    [self->fanhui.layer setBorderColor:[UIColor whiteColor].CGColor];
    [fanhui setFont: [UIFont boldSystemFontOfSize:14]];
    //边框宽度
    [fanhui.layer setBorderWidth:1.0];
    [fanhui setTitleColor:[UIColor whiteColor]forState:UIControlStateNormal];
    [fanhui setTitle:@"返回" forState:UIControlStateNormal];
    [fanhui addTarget:self action:@selector(pressfanhui) forControlEvents:UIControlEventTouchUpInside];
    
    
    //将所有的控件添加到视图中显示
    [self.view addSubview:yhm];
    [self.view addSubview:mm];
    [self.view addSubview:username];
    [self.view addSubview:password];
    [self.view addSubview:zhuce];
    [self.view addSubview:fanhui];
}





//注册事件函数


- (void)presszhuce
{
    NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
    [dict setValue:[NSString stringWithFormat:@"%@",username.text] forKey:@"tel"];
    [dict setValue:[NSString stringWithFormat:@"%@",password.text] forKey:@"password"];
    NSString *urlStr = [NSString stringWithFormat:@"http://172.24.10.175/workout/api.php/reg"];
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager POST:urlStr parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        [self dismissViewControllerAnimated:YES completion:nil];
        NSLog(@"%@",responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
       
    }];
}
    



//返回事件函数
-(void) pressfanhui
{
    LoginViewController *loginVC = [[LoginViewController alloc] init];
    [self presentViewController:loginVC animated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
